/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package javaBean;

import daoGenerico.DAOgenerico;
import entidades.Endereco;
import java.util.ArrayList;
import java.util.List;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.RequestScoped;


/**
 *
 * @author Ana
 */
@ManagedBean
@RequestScoped
public class EnderecoBean {
    private Endereco endereco=new Endereco();
    private final List<Endereco> ender;

    public EnderecoBean() {
        DAOgenerico<Endereco> d=new DAOgenerico<Endereco>(Endereco.class); 
        ender=d.showall();
    }
    
    public Endereco getEndereco(){
        return this.endereco;
    }
    public void grava(){
      DAOgenerico<Endereco> d=new DAOgenerico<Endereco>(Endereco.class);  
      d.add(endereco);
      this.endereco=new Endereco();
    }
    public List<Endereco> completeEndereco(String q){
        List<Endereco> sugestao=new ArrayList<Endereco>();
        for(Endereco e:ender){
            if (e.getDescricao().startsWith(q)){
                sugestao.add(e);
            }
        }return sugestao;
    }
}
